{php include wl_template('common/header');}
<ul class="nav nav-tabs">
    <li ><a href="{php echo web_url('wxplatform/wechat/autoreply')}">回复列表</a></li>
    <li {if empty($id)}class="active"{/if}><a href="{php echo web_url('wxplatform/wechat/creatReply')}">添加回复</a></li>
    {if !empty($id)}
    <li class="active"><a href="#">编辑回复</a></li>
    {/if}
</ul>
<div class="app-content">
    <div class="app-form">
        <form action="" method="post" class="form-horizontal form form-validate" id="form">
            <div class="panel panel-default">
                <div class="panel-heading">自动回复设置</div>
                <div class="panel-body">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">规则名称</label>
                        <div class="col-sm-7 col-xs-12">
                            <input type="text" name="reply[name]" class="form-control" value="{$reply['name']}" />
                        </div>
                    </div>


                    <div class="form-group">
                        <label class="col-sm-2 control-label">排序</label>
                        <div class="col-sm-7">
                            <input type="text" name="reply[displayorder]" class="form-control" value="{$reply['displayorder']}" />
                            <span class="help-block">数字越大，排序越靠前</span>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">状态</label>
                        <div class="col-sm-9">
                            <label class="radio-inline" >
                                <input type="radio" value="1" name="reply[status]" {if $reply['status'] == 1 || empty($id)} checked {/if}>启用
                            </label>
                            <label class="radio-inline" >
                                <input type="radio" value="0" name="reply[status]" {if $reply['status'] == 0} checked {/if}>禁止
                            </label>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">关键字</label>
                        <div class="col-sm-9">
                            <div id="datas">
                                {if empty($reply['kwlist'])}
                                <div class="input-group data-item" style="margin-top: 10px;">
                                    <span class="input-group-addon">关键字</span>
                                    <input type="text" name="keyword[]" class="form-control" value="">
                                    <span class="input-group-addon">触发方式</span>
                                    <select name='kwtype[]' class='form-control'>
                                        <option value='1'>精确触发</option>
                                        <option value='2'>包含触发</option>
                                    </select>
                                    <span onclick="removes(this)" class="input-group-addon btn btn-default data-item-delete"><i class="fa fa-remove"></i> 删除</span>
                                </div>
                                {else}
                                {loop $reply['kwlist'] $kwv}
                                <div class="input-group data-item" style="margin-top: 10px;">
                                    <span class="input-group-addon">关键字</span>
                                    <input type="text" name="keyword[]" class="form-control" value="{$kwv['content']}">
                                    <span class="input-group-addon">触发方式</span>
                                    <select name='kwtype[]' class='form-control'>
                                        <option value='1' {if $kwv['type']==1}selected="selected"{/if} >精确触发</option>
                                        <option value='2' {if $kwv['type']==2}selected="selected"{/if} >包含触发</option>
                                    </select>
                                    <span onclick="removes(this)" class="input-group-addon btn btn-default data-item-delete"><i class="fa fa-remove"></i> 删除</span>
                                </div>
                                {/loop}
                                {/if}
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label"></label>
                        <div class="col-sm-9">
                            <a class="btn btn-info btn-add-type" id="addtype" href="javascript:;" onclick="addType();">
                                <i class="fa fa-plus" title=""></i>增加一个关键字
                            </a>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">回复内容</label>
                        <div class="col-sm-9">
                            <div id="replycontent">
                                {if !empty($reply['baselist'])}
                                {loop $reply['baselist'] $base}
                                <div class='input-group data-item' style='margin-top: 10px;'>
                                    <input type='text' name='contenttext[]' class='form-control' value="{$base['content']}">
                                    <span onclick='removes(this)' class='input-group-addon btn btn-default data-item-delete'><i class='fa fa-remove'></i> 删除</span>
                                </div>
                                {/loop}
                                {/if}
                                {if !empty($reply['imglist'])}
                                {loop $reply['imglist'] $kw $base}
                                {php echo attachment_select2W('contentimg[]',$base['imgurl'],$kw);}
                                {/loop}
                                {/if}
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label"></label>
                        <div class="col-sm-9">
                            <a class="btn btn-info btn-add-type" id="addText" href="javascript:;" onclick="addText();">
                                <i class="fa fa-plus" title=""></i>文字
                            </a>
                            <a class="btn btn-info btn-add-type" id="addImage" href="javascript:;" onclick="addImage();">
                                <i class="fa fa-plus" title=""></i>图片
                            </a>
                            <span class="help-block">多条回复信息会随机回复一条</span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label"></label>
                <div class="col-sm-9">
                    <input type="hidden" name="id" value="{$id}" id="id"/>
                    <input type="submit" name="submit" value="提交" class="btn btn-primary min-width" />
                    <input type="hidden" name="token" value="{$_W['token']}" />
                </div>
            </div>
        </form>
    </div>
</div>
<script>
    function addType() {
        $("#addtype").button("loading");
        var html = "<div class='input-group data-item' style='margin-top: 10px;'>"+
            "<span class='input-group-addon'>关键字</span>"+
            "<input type='text' name='keyword[]' class='form-control' value=''>"+
            "<span class='input-group-addon'>触发方式</span>"+
            "<select name='kwtype[]' class='form-control'>"+
            "<option value='1'>精确触发</option>"+
            "<option value='2'>包含触发</option>"+
            "</select>"+
            "<span onclick='removes(this)' class='input-group-addon btn btn-default data-item-delete'><i class='fa fa-remove'></i> 删除</span>"+
            "</div>";
        $("#datas").append(html);
        $("#addtype").button("reset");
    }
    function removes(asd){
        $(asd).closest('.data-item').remove();
    }


    function addText() {
        $("#addText").button("loading");
        var html = "<div class='input-group data-item' style='margin-top: 10px;'>"+
            "<input type='text' name='contenttext[]' class='form-control' value=''>"+
            "<span onclick='removes(this)' class='input-group-addon btn btn-default data-item-delete'><i class='fa fa-remove'></i> 删除</span>"+
            "</div>";
            $("#replycontent").append(html);
        $("#addText").button("reset");
    }

    var kw = 1000;
    function addImage() {
        $("#addImage").button("loading");
        $.ajax({
            url: "{php echo web_url('wxplatform/wechat/imgdiv')}&kw="+kw,
            cache: false
        }).done(function (html) {
            $("#replycontent").append(html);
            $("#addImage").button("reset");
        });
        kw++;
    }




</script>
{php include wl_template('common/footer');}